package com.travelsupport.ui;

import com.travelsupport.ui.R;
import java.util.List;
import com.travelsupport.myobject.CatalogObj;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CatalogAdapter extends ArrayAdapter<CatalogObj>{
	private final String TAG = com.travelsupport.common.Common.TAG;
	private Context context;
	private List<CatalogObj> data;
	
	public CatalogAdapter(Context context, int textViewResourceId, List<CatalogObj> objects) {
		super(context, textViewResourceId, objects);
		this.context = context;
		this.data = objects;
	}

	public static class ViewHolder{
		public ImageView imgCatalogIcon;
		public TextView tvCatalogName;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		ViewHolder holder;
		
		if(v == null){
			LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.adapter_catalog, null);
			
			holder = new ViewHolder();
			holder.imgCatalogIcon = (ImageView) v.findViewById(R.id.img_catalog_icon);
			holder.tvCatalogName = (TextView) v.findViewById(R.id.tv_catalog_name);
			v.setTag(holder);
		} else {
			holder = (ViewHolder)v.getTag();
		}
		
		final CatalogObj catalogObj = data.get(position);
		if(catalogObj != null){
			Log.i(TAG, "catalogObj.getName(): " + catalogObj.getName());
			holder.tvCatalogName.setText(catalogObj.getName());
			holder.tvCatalogName.setTag(catalogObj.get_id());
		}
		return v;
	}
	
}
